package com.cskaoyan.market.admin.service.impl;

import com.cskaoyan.market.admin.service.MarketAdminRoleService;
import com.cskaoyan.market.admin.vo.AdminRoleVo;
import com.cskaoyan.market.db.domain.MarketRole;
import com.cskaoyan.market.db.domain.MarketRoleExample;
import com.cskaoyan.market.db.mapper.MarketRoleMapper;
import com.cskaoyan.market.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;
import java.util.List;

public class MarketAdminRoleServiceImpl implements MarketAdminRoleService {
    @Override
    public List<AdminRoleVo> getOptions() {
        SqlSession session = MyBatisUtil.getSession();
        MarketRoleMapper mapper = session.getMapper(MarketRoleMapper.class);
        MarketRoleExample marketRoleExample = new MarketRoleExample();
        List<MarketRole> marketRoleList = mapper.selectByExample(marketRoleExample);
        List<AdminRoleVo> adminRoleVoList = new ArrayList<>();
        for (MarketRole marketRole : marketRoleList) {
            AdminRoleVo adminRoleVo = new AdminRoleVo();
            adminRoleVo.setValue(marketRole.getId());
            adminRoleVo.setLabel(marketRole.getName());
            adminRoleVoList.add(adminRoleVo);
        }
        session.commit();
        session.close();
        return adminRoleVoList;
    }
}
